<?php
	$showPage = false; 

	//var_dump($authority->getAuthority("group_manager",$_SESSION['id']));
	if($authority->getAuthority("create_user",$_SESSION['id']) == true)
	{
		$showPage = true;
		$groupsArray = $authority->getGroup();
		
		if($_POST)
		{
		   $checkUserSQLText = " SELECT count(*) as toplam FROM snm_users WHERE user_name = '".$db->escape($_POST['user_name'])."' ";
		   $checkUserSQL = $db->sql($checkUserSQLText);
		   $checkUser = $db->getir($checkUserSQL);
		   if($checkUser['toplam'] == 0)
		   {
				if($db->sql("INSERT INTO snm_users (user_name,password,name_surname,authority_group_id,constituent,global_id) VALUES ('".$db->escape($_POST['user_name'])."','".MD5($_POST['password'])."','".$_POST['name_surname']."',".intval($_POST['authority_group_id']).",".$_SESSION['id'].",'".intval($_POST['global_id'])."') "))
				{
					$hata['sonuc'] = true;
					$hata['aciklama'] = ' User Created.';
				}
				else
				{
					$hata['sonuc'] = false;
					$hata['aciklama'] = ' SQL Query Error. Please Contact Administrator.';
				}
		   }
		   else
		   {
				$hata['sonuc'] = false;
				$hata['aciklama'] = ' User Name Already Exists.';
		   }
		   
		}
		
	}
	
	include "template/create_user.php";
?>
